﻿<!-- #include file="ding.asp" -->
<!-- #include file="mymin.asp" -->
<%
Call Head2()

IF KEY<>0 then
	Call Error2("<title>出错!</title></head><body><div class='main320'>你的权限不足！")
end if

Dim action
action=Request("Action")
IF action="view" Then
	call view
elseiF  action="del" Then
	call del
elseiF  action="edit" Then
	call edit
elseiF  action="add" Then
	call add
elseiF  action="save" Then
	call save
else
	call index
end if

Function index
	%><title>公告管理</title></head><body><div class='main400'><%
	Dim rs,sql
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "SELECT id,name FROM 74hu_gonggao order by id desc"
	Rs.Open Sql,myconn,1,1
	If Not rs.eof	Then
		Dim PageSize,Count,page,pagecount,i
		PageSize=15
		Count=rs.recordcount
		page=getN("page",1)
		if page<1 then page=1
		pagecount=(count+pagesize-1)\pagesize
		if page>pagecount then page=pagecount
		rs.move(pagesize*(page-1))
		For i=1 To PageSize
			If rs.eof Then Exit For
			w i+(page-1)*PageSize&".<a href='gonggo.asp?sid="&sid&"&amp;Action=view&amp;id="&rs("id")&"'>"&nowml(rs("name"))&"</a><br/>"
			rs.moveNext
		Next
		w showPage("gonggo.asp", "", page, pageCount)&""
	Else
		w "(没有公告)"
	end if
	Rs.close
	set rs=nothing
	w ("<br/><a href='gonggo.asp?sid="&sid&"&amp;Action=add'>[发布公告]</a>")
end Function

Function add
%>
<title>发布公告</title></head><body><div class='main400'>
<form method="post" action="gonggo.asp">
标题:<br/><input name="name" maxlength="255" class="input"/><br/>
内容:(支持<a href="ubbcl.asp?sid=<%=sid%>">UBB</a>)<br/>
<textarea name='title' cols='45' rows='20'></textarea><br/>
<input type="hidden" name="sid" value="<%=sid%>"/>
<input type="hidden" name="Action" value="save"/>
<input type="hidden" name="edit" value="add"/>
<input type="submit" value="发布"/>
</form>
<%
end Function

Function edit
	Dim id
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
	if id=""  then
		w "<title>出错!</title></head><body><div class='main320'>ID无效.<br/>"
	else
		Dim rs,sql
		Set Rs = Server.CreateObject("Adodb.Recordset")
		Sql = "SELECT name,title FROM 74hu_gonggao where id="&id
		Rs.Open Sql,myconn,1,1
		if not (rs.bof and rs.eof) then
			%>
<title>修改公告</title></head><body><div class='main400'>
<form method="post" action="gonggo.asp">
标题:<br/><input name="name" value="<%=rs("name")%>" maxlength="255" class="input"/><br/>
内容:(支持<a href="ubbcl.asp?sid=<%=sid%>">UBB</a>)<br/>
<textarea name='title' cols='45' rows='20'><%=rs("title")%></textarea><br/>
<input type="hidden" name="sid" value="<%=sid%>"/>
<input type="hidden" name="id" value="<%=id%>"/>
<input type="hidden" name="Action" value="save"/>
<input type="hidden" name="edit" value="edit"/>
<input type="submit" value="修改"/>
</form>
<%
		else
			w "<title>出错!</title></head><body><div class='main320'>没有该公告!<br/>"
		end if
		Rs.close
		set rs=nothing
	end if
	w "<a href=""gonggo.asp?sid="&sid&""">[公告管理]</a>"
end Function

Function view
	Dim id
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
	if id=""  then
		w "<title>出错!</title></head><body><div class='main320'>ID无效.<br/>"
	else
		w "<title>公告管理</title></head><body><div class='main400'>"
		Dim rs,sql
		Set Rs = Server.CreateObject("Adodb.Recordset")
		Sql = "SELECT name,title,HU_time FROM 74hu_gonggao where id="&id
		Rs.Open Sql,myconn,1,1
		if not (rs.bof and rs.eof)  then
		%>
标题:<%=nowml(rs("name"))%><br/>
内容:<%=nowml(rs("title"))%><br/>
时间:<%=nowml(rs("HU_time"))%><br/>
<a href='gonggo.asp?sid=<%=sid%>&amp;Action=edit&amp;id=<%=id%>'>[编辑]</a> <a href='gonggo.asp?sid=<%=sid%>&amp;Action=del&amp;id=<%=id%>'>[删除]</a><br/>
<%
		else
			w "暂无公告!<br/>"
		end if
		Rs.close
		set rs=nothing
	end if
	w "<a href=""gonggo.asp?sid="&sid&""">[公告管理]</a>"
end Function

Function  del
	Dim id
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
	if id="" then
		w "<title>出错!</title></head><body><div class='main320'>ID无效.<br/>"
	else
		if Request("del")="true" then
			Dim rs,sql
			set rs=server.CreateObject("adodb.recordset")
			Sql = "SELECT * FROM 74hu_gonggao where id="&id
			rs.open sql,myconn,1,3
			if not (rs.bof and rs.eof)  then
				rs.delete
			end if
			Rs.close
			set rs=nothing
			%>
<title>删除公告</title></head><body><div class='main400'>
已成功删除该公告!<br/><%
		else
			%>
<title>删除公告</title></head><body><div class='main400'>
是否要删除该公告?<br/>
<a href='gonggo.asp?sid=<%=sid%>&amp;Action=del&amp;del=true&amp;id=<%=id%>'>[确定删除]</a><br/>
<%
		end if
	end if
	w "<a href=""gonggo.asp?sid="&sid&""">[公告管理]</a>"
end Function

Function save
	Dim name,title,id,flag
	name=Trim(Request("name"))
	title=Trim(Request("title"))
	id=TRim(Request("id"))
	if not isnumeric(id) then id=""
		if name=""  then errmsg=errmsg&"公告标题不能为空<br/>":flag=0
		if title=""  then errmsg=errmsg&"公告内容不能为空<br/>":flag=0
		if Request("edit")="edit" then
		if id=""  then errmsg=errmsg&"ID无效<br/>":flag=0
		if flag<>"0" then
			set rs=server.CreateObject("adodb.recordset")
			sql="select * from 74hu_gonggao where id="&id
			rs.open sql,myconn,1,3
			rs("name")=name
			rs("title")=title
			rs.update()
			Rs.close
			set rs=nothing%>
<title>修改公告</title><meta http-equiv="refresh" content="1;url=gonggo.asp?sid=<%=sid%>"></head><body><div class='main400'>
修改公告成功<br/><br/>
<%
		else
			w "<title>出错!</title></head><body><div class='main320'>"&errmsg&"<br/><br/>"
		end if
	else
		if flag<>"0" then
			set rs=server.CreateObject("adodb.recordset")
			sql="select * from 74hu_gonggao"
			rs.open sql,myconn,1,3
			rs.addnew()
			rs("name")=name
			rs("title")=title
			rs("HU_time")=time_now
			rs.update()
			Rs.close
			set rs=nothing
			%>
<title>发布公告</title><meta http-equiv="refresh" content="1;url=gonggo.asp?sid=<%=sid%>"></head><body><div class='main400'>
发布公告成功<br/><br/>
<%		else
			w "<title>出错!</title></head><body><div class='main320'>"&errmsg&"<br/><br/>"
		end if
	END IF
	w "<a href=""gonggo.asp?sid="&sid&""">[公告管理]</a>"
end Function

Call rootLast2%>
